#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    int removeCoveredIntervals(vector<vector<int>>& intervals) {
        if (intervals.size() < 2) return intervals.size();
        int count = intervals.size();
        sort(intervals.begin(), intervals.end(), [](const vector<int>& left, const vector<int>& right) {
            if (left[0] == right[0])
                return left[1] > right[1];
            return left[0] < right[0]; 
            });

        int index = 0;
        int end = 0;
        while (index < intervals.size()) {
            if (intervals[index][1] <= end)
                --count;
            end = max(end, intervals[index++][1]);
        }
        return count;
    }
};